package com.runa.rccprotocol.dto.generic;

import com.runa.protocol.dto.IResponseData;
import com.runa.protocol.util.ByteUtil;
import com.runa.rccprotocol.dto.ConcentratorRequestData;

import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

public class OriginalConcenRequestData extends ConcentratorRequestData {

    private static final Set<String> OriginalNetwork = new CopyOnWriteArraySet<>();

    public static boolean isOriginal(String address) {
        boolean is = OriginalNetwork.contains(address);
        if (is) {
            OriginalNetwork.remove(address);
        }
        return is;
    }

    private String message;

    public OriginalConcenRequestData(String address, String message) {
        super(address);
        this.message = message;
        setHaveResult(true);
        OriginalNetwork.add(address);
    }

    @Override
    public boolean check(IResponseData data) {
        return true;
    }

    @Override
    public byte[] getData() {
        return ByteUtil.hexStringToByte(message);
    }
}
